from django.db import models

# 商品类别表Category：类别名 cate_name


class Category(models.Model):
    cate_name = models.CharField(max_length=50, verbose_name='类别名')

    class Meta:
        verbose_name_plural = "商品类别表"
        db_table = "category"

    def __str__(self):
        return self.cate_name

# 商品信息表Goods：商品名sku_name  价格price 售价selling_price 默认图片img  商品标题title
# 描述instruction 销量 count 库存stock  cate类别**外键**  是否在销售online


class Goods(models.Model):
    sku_name = models.CharField(max_length=100, verbose_name='商品名字')
    price = models.DecimalField(max_digits=13, decimal_places=2, verbose_name="商品价格")
    selling_price = models.DecimalField(max_digits=13, decimal_places=2, verbose_name="商品销售价格")
    img = models.CharField(max_length=200, verbose_name="商品默认图片")
    title = models.CharField(max_length=30, verbose_name="商品标题", null=True)
    instruction = models.TextField(verbose_name="商品的描述信息")
    count = models.IntegerField(verbose_name="商品销售数量", default=0)
    stock = models.IntegerField(verbose_name="商品库存数量", default=0)
    cate = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name='商品类别')
    online = models.BooleanField("是否在售", default=True)

    class Meta:
        db_table = 'goods'
        verbose_name_plural = "商品信息"

    def __str__(self):
        return self.sku_name

# 商品图片表GoodImg： 图片img  图片描述title good外键所属商品


class GoodImg(models.Model):
    img = models.CharField(max_length=200, verbose_name='图片路径')
    title = models.CharField(max_length=200, verbose_name='图片描述', null=True)
    good = models.ForeignKey(to=Goods, on_delete=models.CASCADE, verbose_name="所属商品")

    class Meta:
        db_table = 'goodimg'
        verbose_name_plural = "商品图片"

    def __str__(self):
        return self.title

# 轮播图Carousel： imgPath图片路径  describes图片描述


class Carousel(models.Model):
    imgPath = models.CharField(max_length=200, verbose_name='轮播图路径')
    describes = models.CharField(max_length=200, verbose_name='图片描述', null=True)

    class Meta:
        db_table = 'carousel_t'
        verbose_name_plural = "轮播图"

    def __str__(self):
        return self.describes


from user.models import User


class GoodsCollect(models.Model):
    user = models.ForeignKey(to=User,on_delete=models.CASCADE,verbose_name='用户')
    goods = models.ForeignKey(to=Goods,on_delete=models.CASCADE,verbose_name='商品')
    class Meta:
        db_table = 'goods_collect'
        verbose_name = '商品收藏'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '%s:%s'%(self.user.username,self.goods.sku_name)













